﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using codefile;

namespace ArleneBarandGrill
{
    public partial class Form5 : Form
    {
        upadteQTY ups = new upadteQTY();
        Data ms = new Data();
        DataTable dtl = new DataTable();
       
        int value, Quantity, Total;
        int CurIndex;
        int tQ;
        int i;
        public Form5()
        {
            InitializeComponent();
            btnadd.Click += new EventHandler(btnadd_Click);
            btnremove.Click += new EventHandler(btnremove_Click);
            btnsearch.Click += new EventHandler(btnsearch_Click);
        }
        void btnsearch_Click(object sender, EventArgs e)
        {
          
           ms.connect();
           ms.querry("SELECT * FROM tblproducts WHERE fID LIKE '%" +txtSearch.Text+"%'");
           if (ms.DTbl.Rows.Count > 0)
           {
               dtl = ms.DTbl;
               txtprodName.Text =dtl.Rows[i]["fProductName"].ToString();
               txtProdPrice.Text = dtl.Rows[i]["fProductPrice"].ToString();
               ProdQuality.Text = dtl.Rows[i]["fProductQty"].ToString();

           }
           ms.close();
        }

        void btnremove_Click(object sender, EventArgs e)
        {
            ms.connect();
            value = int.Parse(dtl.Rows[CurIndex]["fProductQty"].ToString());
            Quantity = int.Parse(ProdQuality.Text);
            Total = value - Quantity;
            //update to database
            upadteQTY qty = new upadteQTY();
            qty.Qty = Total.ToString();
            ms.editQTY(qty, CurIndex);
            MessageBox.Show("Success!!!");
            ms.close();

        }

        void btnadd_Click(object sender, EventArgs e)
        {

            ms.connect();
            value = int.Parse(dtl.Rows[CurIndex]["fProductQty"].ToString());
            Quantity = int.Parse(ProdQuality.Text);
            Total = value + Quantity;
            //update to database
            upadteQTY qty = new upadteQTY();
            qty.Qty = Total.ToString();
            ms.editQTY(qty, CurIndex);
            MessageBox.Show("Success!!!");
            ms.close();

        }
        

    }
}
